library(rgenoud)
library(MASS)
library(Matching)
library(foreign)
library(gmodels)
library(rbounds)
attach(soebasic)
names(soebasic)
Y<-win
Tr<-treat
#Genetic Matching
X<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode)
BalanceMatrix<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode, I(A_ASSETS^2), I(A_AGE^2), I(A_ASSETS*A_AGE), I(A_ASSETS*home),I(A_AGE*home), I(stake_log^2))
gen1<-GenMatch(Tr=Tr, X=X, BalanceMatrix=BalanceMatrix, pop.size=1000,exact=as.logical(c(0,0,0,0,0,1)))
mgen1<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen1)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen1, nboots=1000)
X<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode)
soebasic <- read.dta("/Users/ywang/Documents/My Documents/Research/working papers/political connections and courts/data/working/CPS capture datafile/matching/SOEmatch1.dta")
attach(soebasic)
names(soebasic)
Y<-win
Tr<-treat
X<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode)
BalanceMatrix<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode, I(A_ASSETS^2), I(A_AGE^2), I(A_ASSETS*A_AGE), I(A_ASSETS*home),I(A_AGE*home), I(stake_log^2))
gen1<-GenMatch(Tr=Tr, X=X, BalanceMatrix=BalanceMatrix, pop.size=1000,exact=as.logical(c(0,0,0,0,0,1)))
mgen1<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen1)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen1, nboots=1000)
summary(mgen1)
pribasic <- read.dta ("/Users/ywang/Documents/My Documents/Research/working papers/political connections and courts/data/working/CPS capture datafile/matching/PRImatch1.dta")
attach(pribasic)
names(pribasic)
Y<-win
Tr<-treat
X<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode)
BalanceMatrix<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode, I(A_ASSETS^2), I(A_AGE^2), I(A_ASSETS*A_AGE), I(A_ASSETS*home),I(A_AGE*home), I(stake_log^2))
gen2<-GenMatch(Tr=Tr, X=X, BalanceMatrix=BalanceMatrix, pop.size=1000, exact=as.logical(c(0,0,0,0,0,1)))
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen2, nboots=1000)
mgen2<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen2)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen2, nboots=1000)
summary(mgen2)
soebasic <- read.dta("/Users/ywang/Documents/My Documents/Research/working papers/political connections and courts/data/working/CPS capture datafile/matching/SOEmatch1.dta")
attach(soebasic)
names(soebasic)
Y<-win
Tr<-treat
X<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode)
BalanceMatrix<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode, I(A_ASSETS^2), I(A_AGE^2), I(A_ASSETS*A_AGE), I(A_ASSETS*home),I(A_AGE*home), I(stake_log^2))
gen1<-GenMatch(Tr=Tr, X=X, BalanceMatrix=BalanceMatrix, pop.size=1000,exact=as.logical(c(0,0,0,0,0,1)))
mgen1<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen1)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen1, nboots=1000)
mgen1<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen1,caliber=0.8)
mgen1<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen1,caliper=.8)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen1, nboots=1000)
summary(mgen1)
pribasic <- read.dta ("/Users/ywang/Documents/My Documents/Research/working papers/political connections and courts/data/working/CPS capture datafile/matching/PRImatch1.dta")
attach(pribasic)
names(pribasic)
Y<-win
Tr<-treat
X<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode)
BalanceMatrix<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode, I(A_ASSETS^2), I(A_AGE^2), I(A_ASSETS*A_AGE), I(A_ASSETS*home),I(A_AGE*home), I(stake_log^2))
gen2<-GenMatch(Tr=Tr, X=X, BalanceMatrix=BalanceMatrix, pop.size=1000, exact=as.logical(c(0,0,0,0,0,1)))
mgen2<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen2,caliper=.8)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen2, nboots=1000)
mgen2<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen2,caliper=.5)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen2, nboots=1000)
mgen2<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen2,caliper=.3)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen2, nboots=1000)
summary(mgen2)
mgen2<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen2,caliper=.5)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen2, nboots=1000)
summary(mgen2)
mgen2<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen2,caliper=.8)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen2, nboots=1000)
summary(mgen2)
library(rgenoud)
library(MASS)
library(Matching)
library(foreign)
library(gmodels)
library(rbounds)
soebasic <- read.dta("/Users/ywang/Documents/My Documents/Research/working papers/political connections and courts/data/working/CPS capture datafile/matching/SOEmatch.dta")
attach(soebasic)
names(soebasic)
Y<-win
Tr<-treat
X<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode)
BalanceMatrix<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode, I(A_ASSETS^2), I(A_AGE^2), I(A_ASSETS*A_AGE), I(A_ASSETS*home),I(A_AGE*home), I(stake_log^2))
gen1<-GenMatch(Tr=Tr, X=X, BalanceMatrix=BalanceMatrix, pop.size=1000,exact=as.logical(c(0,0,0,0,0,1)))
mgen1<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen1,caliper=.8)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen1, nboots=1000)
summary(mgen1)
pribasic <- read.dta ("/Users/ywang/Documents/My Documents/Research/working papers/political connections and courts/data/working/CPS capture datafile/matching/PRImatch.dta")
attach(pribasic)
names(pribasic)
Y<-win
Tr<-treat
X<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode)
BalanceMatrix<-cbind(A_ASSETS, A_AGE, contractdispute, home, stake_log, provincecode, I(A_ASSETS^2), I(A_AGE^2), I(A_ASSETS*A_AGE), I(A_ASSETS*home),I(A_AGE*home), I(stake_log^2))
gen2<-GenMatch(Tr=Tr, X=X, BalanceMatrix=BalanceMatrix, pop.size=1000, exact=as.logical(c(0,0,0,0,0,1)))
mgen2<-Match(Y=Y, Tr=Tr, X=X, Weight.matrix=gen2,caliper=.8)
MatchBalance(Tr~A_ASSETS+A_AGE+contractdispute+home+stake_log+provincecode+I(A_ASSETS^2)+I(A_AGE^2)+I(A_ASSETS*A_AGE)+I(A_ASSETS*home)+I(A_AGE*home)+I(stake_log^2), match.out=mgen2, nboots=1000)
summary(mgen2)
